package com.heima.admin.controller.v1;


import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.api.admin.AdChannelControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    /***
     * 新增
     * @param channel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return adChannelService.insert(channel);

    }

    /***
     * 更新
     * @param channel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return adChannelService.update(channel);
    }


    /***
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }
}
